<?phpif (!defined('INC_PATH')) {
	define ('INC_PATH', realpath(dirname(__FILE__).'/../../').'/');
}
require_once INC_PATH.'piwo-v0.2/lib/common.php';
function plugin_toc(Parser $parser, Node $node) {	$indextable = $parser->getUserInfo('indextable');	if ($indextable instanceof IndexTable) {	$o	= '<div class="toc" id="__toc">';	//$o .= '<ul>';	$lastlvl = 0;	foreach($indextable->getAsArray() as $item) {		if ($lastlvl < $item->getLevel()) {			$diff = $item->getLevel() - $lastlvl;			for ($i = 0; $i < $diff; $i++)				$o .= '<ul>';		} elseif ($lastlvl > $item->getLevel()) {			$diff = $lastlvl - $item->getLevel();			for ($i = 0; $i < $diff; $i++)				$o .= '</ul>';		}		$o .= '<li>';		$o .= '<a href="#header_'.($item->getId() - 1).'">'.$item->getId().' '.pw_s2e($item->getText()).'</a>';		$o .= '</li>';		$lastlvl = $item->getLevel();	}	$o .= '</ul>';	$o .= '</div>';	}	return $o;}
function plugin_nstoc(Parser $parser, Node $node) {		$token = new ParserRule($node, $parser);	$cont = $token->getArrayFromNode($node);	$curID = pw_wiki_getid();		//TODO errors should bubble up	//TODO Title should be of the form TITLE=string...	try {		$id = new WikiID(isset($cont[1]) && WikiID::isValidAndAbsolute($cont[1]) ? $cont[1] : $curID->getFullNS());		TestingTools::inform($id->getFullNS());	} catch (Exception $e) {		return nop($e->getMessage());	}			// Parameter TITLE: Print Title	$titeltxt = "";	//TODO do not use position 0 and 1 of the array (1 is the title string)	if (in_array("TITLE", $cont)) {		$titeltxt = utf8_ucwords(str_replace(":", " &raquo; ", $id->isRootNS() ? "[root]" : trim($id->getFullNS(), ":")));		$titeltxt = "Content of namespace <i>\"$titeltxt\"</i>: ";	}	
		// Parameter NOERR: Do not show error messages!	return pw_wiki_nstoc($titeltxt, in_array("NOERR", $cont));}function pw_wiki_nstoc($titel, $error) {		$id = pw_wiki_getid();	$path = WIKISTORAGE.$id->getFullNSPath();		$wikiFiles = array_merge(glob($path."*/", GLOB_ONLYDIR), glob($path."*".WIKIFILEEXT));	sort($wikiFiles);	// 	TestingTools::inform($wikiFiles);	// Titel werden nur ausgegeben, wenn Fehlermeldungen auch ausgegeben werden dürfen!	// ...sonst kann es zu alleinstehenden Titeln kommen.	$out = "";
	if (utf8_strlen($titel) > 0) {		$out .= $titel;	}	if($error && empty($wikiFiles)) {		return $out."<br />".nop("There are no pages in the namespace '".pw_s2e($id->getFullNS())."'.", false);	}		$out .= "<ul>";	$uniqueWikiLinks = array();	foreach($wikiFiles as $file) {		$curId = WikiID::fromPath($file, WIKISTORAGE, WIKIFILEEXT);		if($curId->getPage() == WIKINSDEFAULTPAGE) {			continue;		}		if($curId->isNS()) {			$url = $curId->getFullNSAsUrl();			$name = $curId->getNS();		} else {			$url = $curId->getIDAsUrl();			$name = $curId->getPage();		}		//TestingTools::inform($name);
				if(!in_array($name, $uniqueWikiLinks)) {			$out .= "<li><a href='?id=".$url."'>".pw_s2e(utf8_ucfirst($name))."</a></li>";// 			TestingTools::inform($curId);			$uniqueWikiLinks[] = $name;		}	}	$out .= "</ul>";	//  	TestingTools::inform($uniqueWikiLinks);	return $out;}
function plugin_trace (Parser $parser, Node $node, $sep = "&raquo;") {	$sep = ' '.$sep.' ';	$id = pw_wiki_getid();		$mode = pw_wiki_getmode();	if($id->getID() == ":".WIKINSDEFAULTPAGE || $id->getID() == ":") {		$out = "Home";	} else {		$out = "<a href='?id=".pw_s2url(":".WIKINSDEFAULTPAGE)."'>Home</a>";	}	$current_namespace = "";	foreach ($id->getFullNSAsArray() as $index => $namespace) {		if($id->isNS() && $index == sizeof($id->getFullNSAsArray()) - 1) {			$out .= $sep.pw_s2e(utf8_ucfirst($namespace)); 		} else {			$current_namespace .= $namespace.":";			$out .= $sep."<a href='?id=:$current_namespace'>".pw_s2e(utf8_ucfirst($namespace))."</a>";		}	}		if($id->isNS() || $id->getPage() == WIKINSDEFAULTPAGE) {
		return $out;
	}		return $out.$sep.pw_s2e(utf8_ucfirst($id->getPage()));}?>